<?php
/* --------------------------------------------------------------
   admin_fav_master.php 2009-07-15 gambio
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2009 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/
?><?php

if(defined('_GM_VALID_CALL') === false) die('x0');
if($_SESSION['customers_status']['customers_status_id'] != 0) die('x0');


$act = $_GET['act'];

switch($act)
{
	case 'load_favs':
		$result = xtc_db_query('
			SELECT link_key
			FROM gm_admin_favorites
			WHERE
				customers_id = "'.$_SESSION['customer_id'].'"
			ORDER BY
				sort_order ASC,
				favorites_id ASC
		');
		$out = '';
		while(($row = xtc_db_fetch_array($result) )) 
		{
			$out .= '"'. $row['link_key'] .'",';
		}
		$out = substr($out, 0, strlen($out) - 1);
		$out = strip_tags($out);
		$out = '{"link_keys" : ['.$out.']}';
		echo $out;
		break;
		
	case 'save_fav':
		$link_key = addslashes($_GET['link_key']);
		
		xtc_db_query('
			DELETE FROM gm_admin_favorites
			WHERE link_key = "'.$link_key.'"
			AND customers_id = "'.$_SESSION['customer_id'].'"
		');
		xtc_db_query('
			INSERT INTO gm_admin_favorites
			SET
				customers_id = "'.$_SESSION['customer_id'].'",
				link_key = "'.$link_key.'"
		');
		break;
		
	case 'delete_fav':
		$link_key = addslashes($_GET['link_key']);
		
		xtc_db_query('
			DELETE FROM gm_admin_favorites
			WHERE link_key = "'.$link_key.'"
			AND customers_id = "'.$_SESSION['customer_id'].'"
		');
		break;
		
	default:
}


?>